#!/bin/bash

# 从/etc/passwd文件中提取用户所属的组ID
# 然后根据组ID从/etc/group文件中找到对应的组名

while IFS=: read -r username password uid gid gecos home shell; do
    # 从/etc/group文件中根据gid找到组名
    group_name=$(awk -F: '$3 == gid {print $1}' gid="$gid" /etc/group)
    echo "用户 $username 所属的组名是: $group_name"
done < /etc/passwd
